package com.transaction.demo.base.biz.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.transaction.demo.base.biz.SysAuditLogBiz;
import com.transaction.demo.base.dao.AuditLogDao;
import com.transaction.demo.base.entity.AuditLogBean;
import com.transaction.demo.base.vo.req.AuditLogAddReqVo;
import com.transaction.demo.base.vo.req.AuditLogListReqVo;
import com.transaction.demo.base.vo.req.AuditLogReqVo;
import com.transaction.demo.base.vo.req.AuditLogUpdateReqVo;
import com.transaction.demo.base.vo.resp.AuditLogRespVo;
import com.transaction.demo.common.util.ResultPage;

/**
 * 描述：日志审计表
 * 作者：马庆智
 * 日期：2023/03/28 17:07:13
 */
@Service
public class SysAuditLogBizImpl implements SysAuditLogBiz {

	@Autowired
	private AuditLogDao auditLogDao;

	/**
	 * 查询日志审计表
	 *
	 * @param auditLog 请求参数
	 * @return AuditLogResp
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:13
	 */
	@Override
	public AuditLogRespVo queryAuditLog(AuditLogReqVo auditLog) {

		AuditLogBean query = auditLogDao.queryAuditLog(AuditLogBean.builder().build());

		return AuditLogRespVo.builder().build();
	}

	/**
	 * 查询日志审计表列表
	 *
	 * @param auditLog 请求参数
	 * @return AuditLogResp
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:13
	 */
	@Override
	public ResultPage<AuditLogRespVo> queryAuditLogList(AuditLogListReqVo auditLog) {

		PageHelper.startPage(auditLog.getCurrent(), auditLog.getPageSize());
		List<AuditLogBean> query = auditLogDao.queryAuditLogList(AuditLogBean.builder().build());
		PageInfo<AuditLogBean> pageInfo = new PageInfo<>(query);

		List<AuditLogRespVo> list = pageInfo.getList().stream().map(x -> {
			AuditLogRespVo resp = new AuditLogRespVo();
			BeanUtils.copyProperties(x, resp);
			return resp;
		}).collect(Collectors.toList());

		return new ResultPage<>(list, pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal());

	}

	/**
	 * 添加日志审计表
	 *
	 * @param auditLog 请求参数
	 * @return int
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:13
	 */
	@Override
	public int saveAuditLog(AuditLogAddReqVo auditLog) {

		return auditLogDao.saveAuditLog(AuditLogBean.builder().build());
	}

	/**
	 * 删除日志审计表
	 *
	 * @param ids 请求参数
	 * @return int
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:13
	 */
	@Override
	public int deleteAuditLog(String ids) {
		return auditLogDao.deleteAuditLog(
				Arrays.stream(ids.split(",")).map(Integer::parseInt).collect(Collectors.toList()));
	}

	/**
	 * 更新日志审计表
	 *
	 * @param auditLog 请求参数
	 * @return int
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:13
	 */
	@Override
	public int updateAuditLog(AuditLogUpdateReqVo auditLog) {

		return auditLogDao.updateAuditLog(AuditLogBean.builder().build());
	}

}